import { Route, Link } from 'react-router-dom'
import React from 'react';
import RenderAuthorized from '@lib/components/Authorized';
import { getAuthority } from '@lib/utils/authority';
import { Result, Button } from 'antd';


const noMatch = (
    <Result
        status={403}
        title="403"
        subTitle="Sorry, you are not authorized to access this page."
        extra={
            <Button type="primary">
                <Link to="/signin">Go Login</Link>
            </Button>
        }
    />
);


export const AuthorizedRoute = ({
    authority,
    ...rest
}) => {
    const Authorized = RenderAuthorized(getAuthority());
    return (
        <Authorized
            authority={authority}
            noMatch={noMatch}
        >
            <Route
                {...rest}
            />
        </Authorized>
    )
};

export default AuthorizedRoute;
